<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>实战1</title>
</head>
<body>
    <button>按钮1</button>
    <button>按钮2</button>
    <button>按钮3</button>
    <script>
        const btns = document.getElementsByTagName("button");
        for (let i = 0; i < btns.length; i++) {
            console.log(btns[i]);
            // btns[i].onclick = function (){
            //     alert('你好,'+i);
            // }

            btns[i].onclick = () => {alert('你好,'+i);}
        }
    </script>
</body>
</html>